/*
 * JSFConsole - Lightweight JSF Application Monitor
 * Copyright (C) 2009  Grzegorz Bugaj
 * http://www.gregbugaj.com
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/
package com.gregbugaj.reflector.filter;

import java.util.List;

import javax.el.ArrayELResolver;
import javax.el.BeanELResolver;
import javax.el.CompositeELResolver;
import javax.el.ListELResolver;
import javax.el.MapELResolver;

import com.gregbugaj.jsfconsole.util.FacesUtil;

/**
 * 
 * @author devil
 *
 */
public class ELResolverPropertyFilter extends PropertyFilterStrategy {

	@Override
	public boolean isValidProperty(final String property) {
		if(property==null || property.equals("")){
			return true;
		}
		for (int i=0; i<getPropertyList().size(); i++) {
			if (getPropertyList().get(i).equals(property)) {
				return true;
			} 
		}
		return false;		
	}

	@Override
	public void inspect(final Object objectToInspect) {
		if(objectToInspect==null)return;
		CompositeELResolver  resolver=new CompositeELResolver();
		resolver.add(new BeanELResolver());
		//resolver.add(new ArrayELResolver());
		//resolver.add(new ImplicitObjectELResolver());
		//resolver.add(new ListELResolver());
		//resolver.add(new MapELResolver());
		//resolver.add(new ResourceBundleELResolver());
		//resolver.add(new ScopedAttributeELResolver());
		List<String> properties=FacesUtil.getProperties(resolver, objectToInspect);
		if(properties!=null){
			addProperties(properties.toArray(new String[0]));
		}
	}
}